import static java.lang.Thread.sleep;

public class Demo1 {
    // 线程打断
    private static boolean isQuit = false;

    public static void main(String[] args){
        Thread thread = new Thread(()->{
            while(!isQuit){
                System.out.println("线程正在运行!");
                try {
                    sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程运行结束!");
        });

        thread.start();
        try {
            sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        isQuit = true;
        System.out.println("设置isQuit为true!");
    }
}
